<?php

include 'DBconn.php';

class MarkupHeader {

    public function getNetMarkup() {
        $result = mysql_query("select * from markup_header where markup_type='Net Markup' and activestatus=1") or die(mysql_error());
        $res_arr = array();
        while ($row = mysql_fetch_object($result)) {
            $tmp = new VoMarkupHeader();
            $tmp->serialnumber = (int) $row->serialnumber;
            $tmp->markup_code = $row->markup_code;
            $tmp->markup_remark = $row->markup_remark;
            $tmp->markup_value = $row->markup_value;
            $tmp->markup_type = $row->markup_type;
            $tmp->priceA = (double) $row->priceA;
            $tmp->priceB = (double) $row->priceB;
            $tmp->priceC = (double) $row->priceC;
            $tmp->priceD = (double) $row->priceD;
            $tmp->priceE = (double) $row->priceE;
            $tmp->priceF = (double) $row->priceF;
            $tmp->cre_userid = (int) $row->cre_userid;
            $tmp->cre_datetime = $row->cre_datetime;
            $tmp->activestatus = (boolean) $row->activestatus;
            $res_arr[] = $tmp;
        }
        mysql_free_result($result);
        return $res_arr;
    }

    public function getMarginalMarkup() {
        $result = mysql_query("select * from markup_header where markup_type='Marginal Markup' and activestatus=1") or die(mysql_error());
        $res_arr = array();
        while ($row = mysql_fetch_object($result)) {
            $tmp = new VoMarkupHeader();
            $tmp->serialnumber = (int) $row->serialnumber;
            $tmp->markup_code = $row->markup_code;
            $tmp->markup_remark = $row->markup_remark;
            $tmp->markup_value = $row->markup_value;
            $tmp->markup_type = $row->markup_type;
            $tmp->priceA = (double) $row->priceA;
            $tmp->priceB = (double) $row->priceB;
            $tmp->priceC = (double) $row->priceC;
            $tmp->priceD = (double) $row->priceD;
            $tmp->priceE = (double) $row->priceE;
            $tmp->priceF = (double) $row->priceF;
            $tmp->cre_userid = (int) $row->cre_userid;
            $tmp->cre_datetime = $row->cre_datetime;
            $tmp->activestatus = (boolean) $row->activestatus;
            $res_arr[] = $tmp;
        }
        mysql_free_result($result);
        return $res_arr;
    }

    public function addNewMarkup($VObject) {
        $cls = array();
        $query = "insert into markup_header(markup_code,markup_remark,markup_value,markup_type,priceA,priceB,priceC,priceD,priceE,priceF,cre_userid,cre_datetime,activestatus) values('$VObject->markup_code','$VObject->markup_remark','$VObject->markup_value','$VObject->markup_type','$VObject->priceA','$VObject->priceB','$VObject->priceC','$VObject->priceD','$VObject->priceE','$VObject->priceF','$VObject->cre_userid','$VObject->cre_datetime',1)";
        $s = mysql_query($query) or die(mysql_error());
        if ($s) {
            mysql_query("COMMIT");
        } else {
            mysql_query("ROLLBACK");
        }
        return $this->getAllMarkups();
    }

    public function getAllMarkups() {
        $result = mysql_query("select * from markup_header where activestatus=1") or die(mysql_error());
        $res_arr = array();
        while ($row = mysql_fetch_object($result)) {
            $tmp = new VoMarkupHeader();
            $tmp->serialnumber = (int) $row->serialnumber;
            $tmp->markup_code = $row->markup_code;
            $tmp->markup_remark = $row->markup_remark;
            $tmp->markup_value = $row->markup_value;
            $tmp->markup_type = $row->markup_type;
            $tmp->priceA = (double) $row->priceA;
            $tmp->priceB = (double) $row->priceB;
            $tmp->priceC = (double) $row->priceC;
            $tmp->priceD = (double) $row->priceD;
            $tmp->priceE = (double) $row->priceE;
            $tmp->priceF = (double) $row->priceF;
            $tmp->cre_userid = (int) $row->cre_userid;
            $tmp->cre_datetime = $row->cre_datetime;
            $tmp->activestatus = (boolean) $row->activestatus;
            $res_arr[] = $tmp;
        }
        mysql_free_result($result);
        return $res_arr;
    }

    public function editMarkup($VObject) {
        $query = "update markup_header set markup_code='$VObject->markup_code',markup_remark='$VObject->markup_remark',markup_value='$VObject->markup_value',markup_type='$VObject->markup_type',priceA='$VObject->priceA',priceB='$VObject->priceB',priceC='$VObject->priceC',priceD='$VObject->priceD',priceE='$VObject->priceE',priceF='$VObject->priceF' where serialnumber='$VObject->serialnumber'";
        $s = mysql_query($query) or die(mysql_error());
        if ($s) {
            mysql_query("COMMIT");
        } else {
            mysql_query("ROLLBACK");
        }
        return $this->getAllMarkups();
    }

    public function deleteMarkup($serialnumber) {
        $s = mysql_query("update markup_header set activestatus=0 where serialnumber='$serialnumber'") or die(mysql_error());
        if ($s) {
            mysql_query("COMMIT");
        } else {
            mysql_query("ROLLBACK");
        }
        return "true";
    }

}

//$vo=new VoMarkupHeader();
//$vo->cre_userid=1;
//$vo->serialnumber=10;
//$vo->markup_code="mark1";
//$s=new MarkupHeader;
//echo $s->editMarkup($vo);
class VoMarkupHeader {

    var $serialnumber;
    var $markup_code;
    var $markup_remark;
    var $markup_value;
    var $markup_type;
    var $priceA;
    var $priceB;
    var $priceC;
    var $priceD;
    var $priceE;
    var $priceF;
    var $cre_userid;
    var $cre_datetime;
    var $activestatus;

}

?>